package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.mapper.ProjectMapper;
import com.atguigu.crowd.service.api.ProjectService;
import com.atguigu.crowd.until.ResultEntity;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import crowd.entity.Project;
import crowd.entity.ProjectExample;
import crowd.entity.ProjectVO;
import crowd.entity.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectServiceImpl implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public List<Project> getProject() {

        return projectMapper.selectByExample(new ProjectExample());
    }

    @Override
    public PageInfo<ProjectVO> getPageInfo(String keyword, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        List<ProjectVO> projects = projectMapper.selectProject(keyword);

        return new PageInfo<>(projects);
    }

    @Override
    public void auditProject(Integer id) {

        ProjectExample projectExample = new ProjectExample();
        projectExample.createCriteria().andIdEqualTo(id);

        Project project = new Project();
        project.setStatus(1);

        projectMapper.updateByExampleSelective(project, projectExample);
    }
}
